



function buttonEvents(clientId,offerId,userId) {
	
	var reserveButton = $('#reserveButton'); 
	reserveButton.button();
	
	reserveButton.click(function() {
		saveReservation(clientId, offerId, userId);
		//alert('reserved');
	});
	
}




/**
 * Function to store the reservatin data in the server
 */
function saveReservation(clientId,offerId,userId) {

	$.ajax({
		url:		window.ajaxUrl + '/createReservationAction',
		type:		'POST',		// type of request to make
		async:		true,		// asynchronous/synchronous request
		dataType:	"json",		// type of data returned from server
		
		// data to send
		data:					
		{
			clientId: 		clientId,	
			offerId: 		offerId,
			userId:			userId	
		},

		// request was successful ... 'data' is received from server
		success: 	function(data, textStatus, jqXHR) {
			if(data) {
				var alertDialog = $('#genericAlert');
				alertDialog.html(data.msg);
				alertDialog.dialog({
					width:		350,
					height:		150,
					show: 		'fade',
					hide: 		'fade',
					buttons: {
						"Ok": 		
						function() {
							$(this).dialog("close");
						}
					}
				});
				//alert(data.msg);
				console.log(data.msg);
			}
		},

		// something went wrong ...
		error:		function(jqXHR, textStatus, errorThrown) {	
			
		},
		
		// code to run regardless of success or failure
		complete: function(xhr, status) {
			
		}
	});
}


